package bitoperations;

//不用比较符比大小
public class WhichBigger {
    public static void main(String[] args) {
        int max = getMax(9, 4);
        System.out.println(max);
    }

    public static int getMax(int a, int b){
        int signa = sign(a);
        int signb = sign(b);
        int signc = sign(a - b);
        int difsign = signa ^ signb;//同号为0，不同为1；
        int samesign = flip(difsign); //同号为1，不同为0
        int returnA = difsign * signa + samesign * signc;
        int returnB = flip(returnA);
        return a * returnA + b * returnB;

    }

    private static int sign(int a){
        //正数为1，负数为0
        return flip((a >> 31) & 1);
    }
    private static int  flip(int a){
        return a ^ 1;
    }
}

